package Model;

import Entity.Role;
import Manager.Manager;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author CONG
 */
public class RoleTableModel extends AbstractTableModel {

    private Manager manager;
    
    public RoleTableModel(Manager manager) {
        this.manager = manager;
    }
    
    @Override
    public int getRowCount() {
        return manager.getRoleManager().getSize();
    }
    
    @Override
    public int getColumnCount() {
        return 3;
    }
    
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Role r = manager.getRoleManager().getRole(rowIndex);
        switch (columnIndex) {
            case 0:
                return r.getRoleCode();
            case 1:
                return r.getName();
            case 2:
                return r.getLoanTypeCode();
            default:
                return null;
        }
    }

    public int getSize() {
        return manager.getRoleManager().getSize();
    }

    public Role getRole(int index) {
        return manager.getRoleManager().getRole(index);
    }

    public void getRolesList(ArrayList<Role> r) {
        manager.getRoleManager().getRolesList(r);
    }
}
